package com.qf.util;

import cn.hutool.jwt.JWTUtil;

import javax.servlet.http.HttpServletRequest;

/**
 * @ClassName GetUserId
 * @Description
 * @Author lanzhike
 * @Date 2023/8/14/0014 上午 10:59
 * @Version 1.0
 */
public class UserUtil {

    /**
     * 获取请求中请求头里面token,并解析用户id
     * @param request
     * @return
     */
    public static String getUserId(HttpServletRequest request){
        String token = request.getHeader("token");
        return String.valueOf(JWTUtil.parseToken(token).getPayload().getClaim("user_id"));
    }
}
